local ModelDialog = require("app.widget.ModalDialog")
local InternalLoginView = class("InternalLoginView",ModelDialog)


function InternalLoginView:AccountFilter(strEventName,sender)
    local edit = sender
    if strEventName == "changed" then
    	-- local text = edit:getText()
    	-- local ulen = string.ulen(text)
    	-- if ulen > 8 then
    	-- 	local newStr = string.usubstr(text,8)
     --        if text~=newStr then
    	-- 	    edit:setText(newStr)
     --            display.pushToast(L("lua_code_text_180"))
     --        end
    	-- end
    end
end

function InternalLoginView:ctor()
	InternalLoginView.super.ctor(self)

	local loginRoot = cc.CSLoader:createNode(Res.LoginInternalView,true)
    self:addChild(loginRoot)
    display.doLayout(loginRoot)

    local editorBox = nil
    local textFieldNode = loginRoot:findChild("Panel/InputLayer/name_field")
    if textFieldNode then
	    editorBox = display.replaceTextFieldWithEditBox(textFieldNode)
	    editorBox:registerScriptEditBoxHandler(handler(self,InternalLoginView.AccountFilter))
	end
	self.editorBox = editorBox

	local confirmButton = loginRoot:findChild("Panel/Button_OK")
	if confirmButton then
		confirmButton:addClickEventListener(function(sender) 
			if self.confirmCallback then
				self.confirmCallback(self)
			end
		end)
	end
end

function InternalLoginView:setConfirmCallback(cb)
	self.confirmCallback = cb
end


function InternalLoginView:setInputText( text)
	if self.editorBox then
		self.editorBox:setText(text)
	end
end


function InternalLoginView:getInputText()
	if self.editorBox then
		return self.editorBox:getText()
	end
end


return InternalLoginView